package com.wyz.note.mq.rabbit.provider.controller;

import com.wyz.note.mq.rabbit.provider.constant.BaseConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @Description: 测试生产者推送数据(扇形交换机)
 * @Author: wei yz
 * @Date: 2022/6/12 14:16
 */
@RestController
public class FanoutSendMessageController {
    private static final Logger log = LoggerFactory.getLogger(FanoutSendMessageController.class);

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/sendFanoutMessage")
    public String sendFanoutMessage(String message) {
        String messageId = BaseConstant.messageId;
        String createTime = BaseConstant.createTime;
        Map<String, Object> map = new HashMap<>();
        map.put("messageId", messageId);
        map.put("messageData", message);
        map.put("createTime", createTime);
        log.info("(扇形) 推送数据 ==> messageId: {},message: {},createTime: {}", messageId, message, createTime);
        rabbitTemplate.convertAndSend("fanoutExchange", null, map);
        return "ok";
    }

}
